home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG PD-ROM B4
/
PD-ROM B4.iso
/
Entertainment
/
Strategy
/
Robots
/
bot 1.0.1
/
Tutorial
/
BASIC
/
Bomber
next >
Wrap
Text File
|
1991-06-25
|
2KB
|
80 lines
!
! Bomber
!
! This bot recognizes when it takes damage, and it tries to run
! away when it gets hit.
! Its weapon is a grenade launcher, not an ordinary gun.
!
#DATA
EQU INCR 23
EQU MINDIST 25
DEF damage
DEF scanAt
DEF XX ! Destination coordinates
DEF YY
DEF goX ! Prepared velocities for running away
DEF goY
#CODE BASIC
:Initialize
Gosub CalcPos ! Pick a point to go to
goX = goX * 20 ! Prepare to accelerate an awful lot
goY = goY * 20
damage = $DAMAGE ! Remember current damage level
While (damage == $DAMAGE) ! Until I get hit
begin
ScanAt = ScanAt + INCR
Scan Angle ScanAt
! Don't launch so close that you hit yourself! If the
! enemy is close, aim MINDIST pixels away. But, the
! first check is to see if something was found.
If ($FOUND <> 0) Then If ($DISTANCE >= MINDIST) &
Then Fire Weapon 1, Angle $ANGLE, Distance $DISTANCE
Else Fire Weapon 1, Angle $ANGLE, Distance MINDIST
! Don't bother "locking" on to the enemy, because
! grenades are pretty slow to fire and detonate.
end
Goto Runaway
:RAway
Gosub CalcVel
goX = goX * 2 ! Move there twice as fast.
goY = goY * 2
:Runaway
Velocity goX, goY
If (XX-$XLOC > 30) Then Goto RAway
If (XX-$XLOC < -30) Then Goto RAway
If (YY-$YLOC > 30) Then Goto RAway
If (YY-$YLOC < -30) Then Goto RAway
! If we got this far, we must be within 30 pixels (both X
! and Y) of our destination. Close enough.
Velocity 0, 0
Goto Initialize ! Start all over again.
! These are subroutines. CALCVEL calculates the new velocity
! for moving to point XX,YY. CALCPOS does the same, except
! that it also picks random numbers between 20 and 235 for
! XX and YY.
:CalcPos
XX = Random(215) + 20
YY = Random(215) + 20
:CalcVel
goX = XX - $XLOC
goY = YY - $YLOC
Return
#END